import 'package:get/get.dart';
import 'package:flutter/material.dart';
import '../../../../utils/xin_he_storage.dart';
import '../../../../utils/xin_he_toast.dart';
import 'xin_he_seller_member_state.dart';

class XinHeSellerMemberLogic extends GetxController {
  final XinHeSellerMemberState state = XinHeSellerMemberState();
  final TextEditingController editingController = TextEditingController();


  Future getSearchResult() async {

    state.isShowResultPage.value = true;
  }

  //取消键盘
  void closeKeyboard(){
    if (Get.focusScope?.hasPrimaryFocus == true) {
      Get.focusScope?.unfocus();
    }
  }

  ///清空输入框
  void clearInputContent() {
    editingController.clear();
    inputChange('');

  }

  ///清除历史记录
  void onClearHistory() async {
    await XinHeLocalStorage.remove(XinHeStorage.searchHistory);
    state.historyList.value = [];
  }

  void onInputEditCompleteAction() async{

    closeKeyboard();
    if(state.inputContent.value.isEmpty) {
      XinHeToast.center('请输入搜索内容');
      return;
    }



    state.isShowResultPage.value = true;

    await getSearchResult();
  }

  void onInputSubmitAction() {

  }

  ///输入框输入更改
  void inputChange(String value){
    if(value.isNotEmpty){
      state.isShowDelete.value = true;
    }else {
      state.isShowDelete.value = false;

      state.isShowResultPage.value = false;

    }
    state.inputContent.value = value;

  }
}
